package com.hbnu.service;

import com.hbnu.dao.SystemWordBookDAO;
import com.hbnu.entity.SystemWordBook;
import com.hbnu.entity.Word;

import java.util.List;

public class SystemWordBookService {
    private SystemWordBookDAO systemBookDAO = new SystemWordBookDAO();

    // 获取所有系统词书
    public List<SystemWordBook> getAllSystemBooks() {
        List<SystemWordBook> books = systemBookDAO.getAllSystemBooks();
        if (books.isEmpty()) {
            throw new RuntimeException("未找到系统词书");
        }
        return books;
    }

    // 获取词书中的单词
    public List<Word> getWordsByBookId(int bookId) {
        if (bookId <= 0) {
            throw new IllegalArgumentException("词书ID必须为正数");
        }

        List<Word> words = systemBookDAO.getWordsBySystemBookId(bookId);
        if (words.isEmpty()) {
            throw new RuntimeException("该词书中没有单词");
        }
        return words;
    }
}